//
//  CZBaseTableViewController.swift
//  XLWB009
//
//  Created by apple on 3/22/16.
//  Copyright © 2016 apple. All rights reserved.
//

import UIKit

class CZBaseTableViewController: UITableViewController {

   //判断用户是否登陆
//    var userLogin=false
    var userLogin=CZUserAccoutModel.sharedInstance.userLogin
    override func loadView(){
        
        userLogin ? super.loadView():setupVisitorView()
    }
    
    //设置方式试图
    func setupVisitorView(){
        view=visitorView
        
        if self is CZHomeViewController{
            
            visitorView.startRotationAnimation()
            
        }else if self is CZMessViewController{
        
            visitorView.setUpVisitorinfo("visitordiscover_image_message", messge: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }else if self is CZDisViewController{
        
            visitorView.setUpVisitorinfo("visitordiscover_image_message", messge: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is CZProfileViewController
        {
            visitorView.setUpVisitorinfo("visitordiscover_image_profile", messge: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        
        //设置代理
        visitorView.delegate=self
//        view.backgroundColor=UIColor.brownColor()
        
        //添加导航栏按钮
        navigationItem.rightBarButtonItem=UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)
        navigationItem.leftBarButtonItem=UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)
    }
    
    private lazy var visitorView:CZVisitorView=CZVisitorView()
}

extension CZBaseTableViewController:CZVisitorViewDelegate{

    //实现协议的方法
    func visitorViewDidClickReterButton() {
        let netWork=CZNxetWorkTool.sharedInstance
//        print("netWork:\(netWork)")
        
//        print("__FUNCTION__")
    }
    
    func visitorViewDidClickLoginButton() {
        let netWork=CZNxetWorkTool.sharedInstance
//        print("netWork:\(netWork)")
        
        //弹出界面登陆
        let oauth=CZOauthViewController()
       
        //Model出控制器
        presentViewController(UINavigationController(rootViewController: oauth), animated: true, completion: nil)
    }
}